package com.yycx.module.bus.provider.service.hy.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.mybatis.query.CriteriaSave;
import com.yycx.module.bus.client.entity.hy.BusErpOrderDetails;
import com.yycx.module.bus.provider.mapper.hy.BusErpOrderDetailsMapper;
import com.yycx.module.bus.provider.service.hy.BusErpOrderDetailsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

/**
 * 海鹰erp订单接口实现类
 *
 * @author flyme
 * @date 2023-01-31
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BusErpOrderDetailsServiceImpl extends BaseServiceImpl<BusErpOrderDetailsMapper, BusErpOrderDetails> implements BusErpOrderDetailsService {


    @Override
    public ResultBody beforeAdd(CriteriaSave cs, BusErpOrderDetails beo, EntityMap extra) {
        return ResultBody.ok();
    }


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<BusErpOrderDetails> cq, BusErpOrderDetails beo, EntityMap requestMap) {
        cq.eq("orderNo", cq.getParams("orderNo"));
        cq.eq("orderType", cq.getParams("orderType"));
        cq.orderByDesc("beod.createTime");
        return ResultBody.ok();
    }


    @Override
    public ResultBody beforeListEntityMap(CriteriaQuery<BusErpOrderDetails> cq, BusErpOrderDetails busErpOrderDetails, EntityMap requestMap) {
        cq.eq(BusErpOrderDetails.class, "orderNo");
        cq.eq(BusErpOrderDetails.class, "orderType");
        cq.orderByDesc("beod.createTime");
        return super.beforeListEntityMap(cq, busErpOrderDetails, requestMap);
    }


    @Override
    @DS("master")
    public List<EntityMap> selectListByOrderNo(String dbName,String orderNo) {
        CriteriaQuery cq = new CriteriaQuery(BusErpOrderDetails.class);
        cq.eq(true, "orderNo", orderNo);
        cq.eq(true, "erpDbName", dbName);
        return selectEntityMap(cq);
    }

    @Override
    @DS("master")
    public List<BusErpOrderDetails> selectListByOrderNos(String dbName,List<String> orderNos) {
        CriteriaQuery cq = new CriteriaQuery(BusErpOrderDetails.class);
        cq.in(true, "orderNo", orderNos);
        cq.eq(true, "erpDbName", dbName);
        return list(cq);
    }
}
